import org.junit.Test;

import java.lang.reflect.Array;
import java.util.*;

/*
 *@description 最长回文子串
 *@author hkfan
 *@version 1.0
 *@create 2025/6/23 16:50
 */
public class Test01 {


    public String longestPalindrome(String s) {
        String res  = "";
        for (int i = 0; i < s.length(); i++) {
            String str1 = search(s,i,i);
            String str2 = search(s,i,i+1);
            String str = (str1.length()>str2.length())?str1:str2;
            res = (res.length()>str.length())?res:str;

        }
        return res;
    }

    private String search(String s, int i, int j) {
        if (i<0 || j>s.length()-1){
           return "";
        }
        while (true){
            if (s.charAt(i)==s.charAt(j)){
                i--;j++;
            }else {
                break;
            }
            if (i<0 || j>s.length()-1){
                break;
            }
        }
        return s.substring(i+1,j);
    }


}